home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
ysmaze
/
demo.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
6KB
|
285 lines
#include <stdio.h>
#include <egb.h>
#include <mos.h>
#include <snd.h>
#include <ys11c.h>
#include <ysutyc.h>
#include <ysmaze.h>
#define MX 32
#define MY 24
char EGB_work[EgbWorkSize];
char MOS_work[MosWorkSize];
char SND_work[16*1024];
struct menuStyle mn={3,3, 2,2, 3, 8,16};
struct fontSize fnt={8,16};
int loadMaze(char *fname,struct mazeStyle *mz,short *dat)
{
int fl;
FILE *fp;
fp=fopen(fname,"rb");
if(fp==NULL)return -1;
fl=YSC_fsize(fp)-16;
fread(&(*mz).bl,4,1,fp);
fread(&(*mz).bh,4,1,fp);
fread(&(*mz).lx,4,1,fp);
fread(&(*mz).ly,4,1,fp);
fread(dat,1,fl,fp);
fclose(fp);
return 0;
}
void turn(int *dir,int ofset)
{
*dir=(*dir+ofset)&65535;
}
void progress(struct mazeStyle *mz,short *dat,int *x,int *y,int dir,int v)
{
int vx,vy;
int lx=(*mz).bl * (*mz).lx;
int ly=(*mz).bl * (*mz).ly;
int x2,y2,bx,by,bx2,by2;
vx=-YCC_sin(v,dir);
vy=-YCC_cos(v,dir);
bx=(*x/(*mz).bl);
by=(*y/(*mz).bl);
x2= *x+vx;
while(x2< 0)x2+=lx;
while(x2>=lx)x2-=lx;
bx2= x2/(*mz).bl;
if (vx>0 && bx2!=bx && YSC_mazePass(mz,dat,bx,by,3))return;
else if(vx<0 && bx2!=bx && YSC_mazePass(mz,dat,bx,by,1))return;
else bx=bx2;
y2= *y+vy;
while(y2< 0)y2+=ly;
while(y2>=ly)y2-=ly;
by2= y2/(*mz).bl;
if (vy>0 && by2!=by && YSC_mazePass(mz,dat,bx,by,2))return;
else if(vy<0 && by2!=by && YSC_mazePass(mz,dat,bx,by,0))return;
*x=x2;
*y=y2;
}
void radar(struct mazeStyle *mz,
int sx,int sy,int c1,int px,int py,int c2,int mx,int my,int l)
{
int bl=(*mz).bl;
px/=bl; py/=bl; mx/=bl; my/=bl;
if(c1==c2 && px==mx && py==my)return;
YGB_color(EGB_work,31);
YGB_writeMode(EGB_work,XOR);
px=sx+px*l; py=sy+py*l; mx=sx+mx*l; my=sy+my*l;
if(c1)YGB_boxFul(EGB_work,px,py,px+l-2,py+l-2);
if(c2)YGB_boxFul(EGB_work,mx,my,mx+l-2,my+l-2);
}
void playGame(struct mazeScreen *ms,struct mazeStyle *mz,short *dat)
{
int fin=0;
int px,py,mx,my,dir,pad;
int buf[640*9];
int rx0,ry0,rx1,ry1,rl;
mx=(*mz).bl /2;
my=(*mz).bl /2;
dir=49152;
rl=((*ms).y1 -(*ms).y0)/(*mz).ly;
rx0=(*ms).x1+1;
ry0=(*ms).y0;
rx1=rx0+rl*(*mz).lx+1;
ry1=ry0+rl*(*mz).ly;
YGB_cls(EGB_work);
YGB_color(EGB_work,0);
YGB_boxFul(EGB_work,rx0+1,ry0+1,rx1-1,ry1-1);
YGB_color(EGB_work,32767);
YGB_print(EGB_work,10,150,"PAD ↑↓←→: MOVE");
YGB_print(EGB_work,10,166," A : GIVE UP");
YGB_box(EGB_work,rx0,ry0,rx1,ry1);
YGB_line(EGB_work,rx1,ry1,rx1-rl,ry1-rl);
YGB_line(EGB_work,rx1,ry1-rl,rx1-rl,ry1);
radar(mz,rx0+1,ry0+1,0,0,0,1,mx,my,rl);
while(fin==0)
{
YSC_mazeGetLines(mz,ms,dat,mx,my,dir,1500,buf);
YSC_mazeDrawWalls(EGB_work,mz,ms,buf);
pad=255;
while(pad!=255)SND_joy_in_2(0,&pad);
while(pad==255)SND_joy_in_2(0,&pad);
if(!(pad & 16))fin=1;
px=mx; py=my;
if(!(pad & 1))progress(mz,dat,&mx,&my,dir, (*mz).bl/5);
if(!(pad & 2))progress(mz,dat,&mx,&my,dir,-(*mz).bl/5);
if(!(pad & 4))turn(&dir, 2048);
if(!(pad & 8))turn(&dir,-2048);
radar(mz,rx0+1,ry0+1,1,px,py,1,mx,my,rl);
if(mx/(*mz).bl==(*mz).lx-1 && my/(*mz).bl==(*mz).ly-1)fin=2;
}
switch(fin)
{
case 1:
YSC_dispWalls
(EGB_work,mz,rx0+1,ry0+1,dat,0,0,(*mz).lx-1,(*mz).ly-1,rl);
YSC_waitMessage(EGB_work,"Give Up!(^_^)",100,10,10,&fnt);
break;
case 2:
YSC_waitMessage(EGB_work,"Congratulations!!",100,10,10,&fnt);
break;
}
}
void egbset(int smod)
{
int resx,resy,mlt;
switch(smod)
{
case 3:
case 12:
resx=640;
resy=480;
mlt=1;
break;
case 10:
resx=320;
resy=240;
mlt=2;
break;
}
EGB_init(EGB_work,EgbWorkSize);
EGB_resolution(EGB_work,0,smod);
EGB_resolution(EGB_work,1,smod);
EGB_displayPage(EGB_work,0,3);
EGB_writePage(EGB_work,0);
EGB_displayStart(EGB_work,0,0,0);
EGB_displayStart(EGB_work,2,mlt,mlt);
EGB_displayStart(EGB_work,3,resx,resy);
EGB_color(EGB_work,1,32768);
EGB_partClearScreen(EGB_work);
EGB_writePage(EGB_work,1);
EGB_displayStart(EGB_work,0,0,0);
EGB_displayStart(EGB_work,2,mlt,mlt);
EGB_displayStart(EGB_work,3,resx,resy);
EGB_color(EGB_work,1,32768);
EGB_partClearScreen(EGB_work);
EGB_mask(EGB_work,0);
}
void main(int argc,char *argv[])
{
int smod=10;
int fin=0,lf=0,sel;
char *intro[]={"☆☆☆ 3次元迷路 ☆☆☆ by YS-11",
"このプログラムはパッドのみで操作し",
"ます。一番左上からスタートしますの",
"で、一番右下に辿り着いてください。",};
char *menu[]={"ゲーム","終了","画面モード"};
short dat[ MX*MY+1 ];
struct mazeStyle mz;
struct mazeScreen ms={80,60, 0,0,160,120,
24*1024+24*32+24,10*1024+10*32+10,
5, 64};
mz.bl=500;
mz.bh=500;
mz.lx=24;
mz.ly=24;
if(argc>=2)
{
lf=1;
if(loadMaze(argv[1],&mz,dat))
{
printf("Load Error\n");
exit(-1);
}
}
egbset(smod);
SND_init(SND_work);
MOS_start(MOS_work,MosWorkSize);
MOS_resolution(0,smod);
MOS_resolution(1,smod);
MOS_color(1,0x7fffffff);
MOS_writePage(0);
MOS_horizon(0,319);
MOS_vertical(0,239);
MOS_setpos(128,120);
MOS_disp(0);
YSC_waitInformation(EGB_work,intro,4,30,30,&fnt);
while(fin==0)
{
char *stack;
if(lf==0)
{
int i;
for(i=0; i<(mz.lx)*(mz.ly); i++)dat[i]=0;
YSC_mazeCreate(&mz,dat);
YGB_cls(EGB_work);
}
dat[(mz.ly)*(mz.lx)-1] |= 64;
YSC_dispWalls(EGB_work,&mz,0,0,dat,0,0,mz.lx-1,mz.ly-1,9);
stack=YSC_pushMenuArea(EGB_work,&mn,220,10,3,menu);
sel=YSC_waitMenu(EGB_work,&mn,220,10,3,menu);
YSC_popScreenBlock(EGB_work,stack);
switch(sel)
{
case 1:
YGB_cls(EGB_work);
playGame(&ms,&mz,dat);
break;
case 2:
fin=1;
break;
case 3:
if (smod== 3)smod=12;
else if(smod==12)smod=10;
else if(smod==10)smod= 3;
egbset(smod);
MOS_resolution(0,smod);
MOS_resolution(1,smod);
MOS_color(1,0x7fffffff);
break;
}
}
MOS_end();
SND_end();
}